<template>
	<app-layout>
		
	
		<view class="sixheader">
			<view class="six">
				<!-- <view class="" @click="helpvideo">
					帮助视频
				</view> -->
				<view class="" @click="setShow">
					个人主页
				</view>
				<u-popup v-model="show" mode="left" border-radius="14" @close="show = false" v-if="show"
					:safeAreaInsetBottom="true" borderRadius="0">
					<view class="model" @touchmove.stop.prevent>
						<view class="info" @click="tomine">
							<view class="avatar">
								<image class="img" :src="userInfo.options.avatar" mode=""></image>
							</view>
							<view class="nickname">
								<view class="nick-nick t-omit-three">{{userInfo.nickname}}</view>
							</view>
							<view class="click">
								<view class="image">
									<image class="arrow" src="/static/image/arred.png" mode=""></image>
								</view>
								<view class="zi">
									点击
								</view>
							</view>
						</view>
						<scroll-view scroll-y class="f-scroll">
							<view class="fscr-item" @click="helpvideo">
								帮助视频
							</view>
							<view class="fscr-item" @click="tomager">
								视频管理
							</view>
							<view class="fscr-item" @click="tofolist">
								关注的人
							</view>
							<view class="fscr-item" @click="tocenter">
								点击进入个人中心
							</view>
						</scroll-view>
						<view class="ftip">
							经常察看双熙堂提供的主题，方便自己学习，方便自己搜索
							<view class="fche" @click="setheshow">
								点击查看
							</view>
						</view>
					</view>
				</u-popup>
				<u-popup :safeAreaInsetBottom="true" v-model="theshow" mode="bottom" border-radius="14"
					@close="theshow = false" v-if="theshow">
					<view class="fmodel" @touchmove.stop.prevent>
						<view class="f-top dir-left-nowrap main-between cross-center">
							<view class="f-title">经常察看双熙堂提供的主题，方便自己学习，方便自己搜索</view>
							<view class="f-image" @click="theshow = false">
								<image class="f-img" src="/static/image/icon/icon-close.png"></image>
							</view>
						</view>
						<view class="scroll-fc">
							<scroll-view scroll-x class="cl-scroll" @scrolltolower="morethemefly">
								<view class="cl-item" @click="changeStatus(clapid)"
									:class="claid == clapid ? 'cl-item-active' : claid == clapid">全部</view>
								<view class="cl-item" v-for="(item) in clatheme" :key="item.id"
									@click="changeStatus(item.id)"
									:class="claid == item.id ? 'cl-item-active' : claid == item.id">
									{{item.title}}
								</view>
							</scroll-view>
						</view>
						<scroll-view scroll-y class="f-scroll" @scrolltolower="tomoretheme">
							<view class="f-item" v-for="(item,index) in themet" :key="index" @click="techange(item)">
								{{item.title}}
							</view>
						</scroll-view>
					</view>
				</u-popup>
			</view>
			<view class="six">
				<view class="flex">
					<view class="item" :class="videoid == item.id ? 'active' : ''" v-for="(item,index) in videolist"
						:key="index">
						{{item.title}}
					</view>
				</view>
			</view>
			<view class="six">
				<view class="flex">
					<view class="sitem" @click="search">
						<image class="seaimg" src="../../static/image/icon/icon-search.png" mode=""></image>
					</view>
					<view class="sitem fitem" @click="release">
						发布
					</view>
				</view>
			</view>
		</view>
		<view class="" style="margin-top: 92rpx;">
			<!-- 9.24 -->
			<xyz-masonry :value="list" @itemClick="itemClick" />
		</view>
		<view class="no-goods" style="margin-top: 152rpx;" v-if="list.length == 0">
			{{listtext}}
		</view>
		<view class="release" :style="{bottom:BotHeight + 'rpx'}" @click="release">
			发布
		</view>
		<!-- 返回顶部 -->
		<view class="quick-box dir-top-nowrap" style="bottom: 180rpx" v-if="opacity == 1">
			<image @click="backTop" class="quick-btn" src="../../static/image/icon/back-top.png"></image>
		</view>
		<view class="">
			<tastlist flobottom="276rpx" floright="0" ref="task"></tastlist>
		</view>
		<app-tab-bar></app-tab-bar>
		</app-layout>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from "vuex";
	import xyzMasonry from './components/xyz-masonry.vue';
	import uPopup from '../../components/basic-component/u-popup/u-popup.vue';
	import appTabBar from "../../components/basic-component/app-tab-bar/app-tab-bar.vue"
	import tastlist from '../../pages/tasklist/tasklist.vue'

	let pagecount = 1

	// 一级分类 9.29
	let fpage = 1
	let fpage_count = 1
	export default {
		components: {
			xyzMasonry,
			uPopup,
			tastlist,
			"app-tab-bar":appTabBar
		},
		data() {
			return {
				show: false,
				theshow: false,
				list: [],
				reqLock: false,
				page: 1,
				limit: 10,
				// pagecount: 1,
				totalcount: 1,
				videolist: [
					/* {
						id: 0,
						title: '收藏'
					}, */
					{
						id: 1,
						// title: '推荐'
						title: '网上珠宝店主带货精选'
					},
				],
				videoid: 1,
				// 返回顶部
				top: 400,
				scrollTop: 0,
				opacity: 0,

				listtext: '正在加载中',

				// 9.29 主题
				clapid: 0,
				claid: 0,
				themet: [],
				clatheme: [],
				fpage: 1,
				fpage_count: 1,
			}
		},
		watch: {
			// 返回顶部
			showBackTop(nVal, oVal) {
				// 当组件的显示与隐藏状态发生跳变时，修改组件的层级和不透明度
				// 让组件有显示和消失的动画效果，如果用v-if控制组件状态，将无设置动画效果
				if (nVal) {
					this.opacity = 1;
				} else {
					this.opacity = 0;
				}
			},
		},
		created() {
			const height = [];
			this.fallData = this.list.fill('').map((item, index) => {
				return {
					height: height[Math.floor(Math.random() * height.length)],
					id: index
				};
			});
		},
		mounted() {
			this.list = []
			this.page = 1
			this.getVideoList()
		},
		onShow() {
			// 11.16 刷新个人信息
			this.$store.dispatch('user/refresh');
			/* let isgoods = this.$storage.getStorageSync('isgoods')
			if (isgoods) {
				this.$storage.removeStorageSync('isgoods')
			}
			let hivideoid = this.$storage.getStorageSync('hivideoid')
			if (hivideoid) {
				this.$storage.removeStorageSync('hivideoid')
			}
			let hivdianid = this.$storage.getStorageSync('sharestoreid')
			if (hivideoid) {
				this.$storage.removeStorageSync('sharestoreid')
			}
			this.list = []
			this.page = 1
			this.getVideoList() */
			// 9.27 调用父组件的方法 免费得金币
			if (this.$refs.task.show || this.$refs.task.isshow) {
				// 9.29 将showMo方法改为judgetask
				this.$refs.task.judgetask()
			}
		},
		onLoad() {
			let isgoods = this.$storage.getStorageSync('isgoods')
			if (isgoods) {
				this.$storage.removeStorageSync('isgoods')
			}
			let hivideoid = this.$storage.getStorageSync('hivideoid')
			if (hivideoid) {
				this.$storage.removeStorageSync('hivideoid')
			}
			// 9.14
			/* let sharestoreid = this.$storage.getStorageSync('sharestoreid')
			if (sharestoreid) {
				this.$storage.removeStorageSync('sharestoreid')
			} */
			// this.list = []
			// this.page = 1
			// this.getVideoList()
		},
		// 9.29 离开页面改变 弹窗显示状态
		onUnload() {
			getApp().globalData.firstapplet = false
		},
		onHide() {
			this.show = false
			this.theshow = false
		},
		/* mounted() {
			this.getVideoList();
		}, */
		// 返回顶部
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			if (pagecount > this.page) {
				this.page++
				this.getVideoList()
			} else {
				/* let agetvideo = this.$storage.getStorageSync('agetvideo')
				if(agetvideo){
					this.list = this.list.concat(agetvideo)
				} else{
					this.page = 1
					this.getVideoList()
				} */
			}
		},
		onPullDownRefresh() {
			if (this.show == false) {
				this.list = []
				this.page = 1
				this.getVideoList()
			}
		},
		computed: {
			// 返回顶部
			showBackTop() {
				// 由于scrollTop为页面的滚动距离，默认为px单位，这里将用于传入的top(rpx)值
				// 转为px用于比较，如果滚动条到顶的距离大于设定的距离，就显示返回顶部的按钮
				return this.scrollTop > uni.upx2px(this.top);
			},
			...mapGetters('iPhoneX', {
				BotHeight: 'getBotHeight',
				emptyHeight: 'getEmpty',
			}),
			...mapState({
				userInfo: state => state.user.info
			}),
		},
		methods: {
			tomine() {
				uni.navigateTo({
					url: '/pages/sixty/user-center/user-center'
				})
			},
			setShow() {
				if (this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken ===
					null) {
					this.$store.dispatch('user/accessToken');
					return;
				}
				this.show = true;
				this.theshow = false
			},
			// 9.29 主题
			setheshow() {
				this.theshow = true
				this.clapid = 0
				this.claid = 0
				this.themet = []
				this.clatheme = []
				this.fpage = 1
				this.fpage_count = 1
				fpage = 1
				fpage_count = 1
				this.thechange(0, 0)
				this.thechange(0, 1)
			},
			// 一级分类更多 9.9
			morethemefly() {
				if (fpage < fpage_count) {
					fpage++
					// this.thechange()
					this.thechange(0, 0)
				}
			},
			// 选择分类更多
			tomoretheme(e) {
				if (this.fpage < this.fpage_count) {
					this.fpage++
					// this.thechange()
					if (this.claid == 0) {
						this.thechange(this.claid, 1)
					} else {
						this.thechange(this.claid, 0)
					}
				}
			},
			thechange(pid = 0, type = 0) {
				let redata = {
					page: this.fpage,
					pid: pid,
					limit: 50
				}
				if (type == 1) {
					redata.type = 1
				}
				// 一级分类 9.9
				if (pid == 0 && type == 0) {
					redata.page = fpage
				}
				this.$request({
					url: this.$api.sixty.cate,
					data: redata
				}).then(res => {
					// console.log(res);
					if (pid == 0) {
						if (type == 1) {
							this.themet = this.fpage == 1 ? res.data.list : this.themet.concat(res.data.list)
							this.fpage_count = res.data.pagination.page_count
						} else {
							// 9.9
							this.clatheme = fpage == 1 ? res.data.list : this.clatheme.concat(res.data.list)
							fpage_count = res.data.pagination.page_count
						}
					} else {
						this.themet = this.fpage == 1 ? res.data.list : this.themet.concat(res.data.list)
						this.fpage_count = res.data.pagination.page_count
					}
				}).catch()
			},
			// 主题分类切换
			changeStatus(id) {
				this.claid = id
				this.themet = []
				this.fpage = 1
				this.fpage_count = 1
				if (id == 0) {
					this.thechange(id, 1)
				} else {
					this.thechange(id)
				}
			},
			techange(item) {
				this.themetid = item.id
				this.themetitle = item.title
				this.show = false
			},

			helpvideo() {
				uni.navigateTo({
					url: '/pages/turnover/videolist?type=2&title=帮助视频'
				})
			},
			tomager() {
				uni.navigateTo({
					url: '/pages/sixty/delete/delete'
				})
			},
			tofolist() {
				uni.navigateTo({
					url: '/pages/sixty/follow/follow'
				})
			},
			search() {
				uni.navigateTo({
					url: '/pages/sixty/search/search'
				})
			},
			tocenter() {
				uni.navigateTo({
					url: '/pages/user-center/personal/personal'
				})
			},
			release() {
				if (this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken ===
					null) {
					this.$store.dispatch('user/accessToken');
					return;
				} else {
					if (this.userInfo.vdian_id != null) {
						this.appStatus(this.userInfo.vdian_id)
					} else {
						uni.showModal({
							content: '请先成为珠宝店主才可发布哦',
							confirmText: '成为店主',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/bepartner/apply/apply'
									})
								}
							}
						});
					}
					// uni.navigateTo({
					// 	url: '/pages/sixty/release/release'
					// })
				}
			},
			appStatus(id) {
				let self = this
				self.$request({
					url: self.$api.apply.store,
					data: {
						id: id
					},
					method: 'get',
				}).then(res => {
					if (res.data.review_status == 0) {
						uni.showModal({
							content: '珠宝店主审核通过后才可发布哦',
							confirmText: '查看进度',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/bepartner/apply/apply'
									})
								}
							}
						});
					} else if (res.data.review_status == 1) {
						uni.navigateTo({
							url: '/pages/sixty/release/release'
						})
					} else if (res.data.review_status == 2) {
						uni.showModal({
							content: '请先成为珠宝店主才可发布哦',
							confirmText: '成为店主',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/bepartner/apply/apply'
									})
								}
							}
						});
					} else if (res.data.review_status == 3) {
						uni.showModal({
							content: '请先成为珠宝店主才可发布哦',
							confirmText: '成为店主',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '/pages/bepartner/apply/apply'
									})
								}
							}
						});
					}
					// console.log(res);
				}).catch(e => {

				})
			},
			// 返回顶部
			backTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			// 获取数据
			getVideoList() {
				/* if (this.reqLock) {
					return;
				} */
				// this.reqLock = true;
				this.$showLoading();
				this.$request({
					url: this.$api.sixty.list,
					data: {
						page: this.page,
						page_size: this.limit,
						review_status: 1
					}
				}).then((res) => {
					// console.log(res);
					this.$hideLoading();
					uni.stopPullDownRefresh()
					pagecount = res.data.pagination.page_count

					this.list = this.list.concat(res.data.list);
					this.$storage.setStorageSync('agetvideo', this.list)
					if (res.code != 0 || this.list.length == 0) {
						this.listtext = '暂无发布视频'
					}
				}).catch(err => {
					this.listtext = '暂无发布视频'
					this.$hideLoading();
					uni.stopPullDownRefresh()
					// console.log(err);
					if (err.msg) {
						uni.showToast({
							icon: 'none',
							title: err.msg
						})
					}
				})
			},
			// 瀑布流元素被点击
			itemClick(id) {
				// console.log(id);
				uni.navigateTo({
					url: `/pages/sixty/fullscreen/index?id=${id}`,
				})
			},
			// 进入视频页
			goVideoPage() {
				uni.navigateTo({
					url: `/pages/sixty/fullscreen/index`,
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.index-waterfall {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: flex-start;

		.column {
			flex: 0 0 calc(50% - 10rpx);
			display: flex;
			flex-direction: column;
		}

		.ceil {
			width: 100%;
			float: left;
			margin-top: 30rpx;
			background-color: #fff;
		}
	}



	.model {
		width: 521rpx;
		padding: 24rpx 32rpx 24rpx 50rpx;

		.info {
			display: flex;
			align-items: center;
			position: relative;

			.avatar {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;

				.img {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.click {
				// position: absolute;
				// bottom: -52px;
				// right: 72px;
				font-size: 26rpx;
				color: #ff2200;
				background: #fff;
				padding: 5rpx;
				text-align: center;

				position: absolute;
				bottom: -48px;
				left: 100rpx;
				display: flex;
				align-items: flex-end;

				.image {
					// width: 198rpx;
					// height: 24rpx;
					// transform: rotate(225deg);
					// position: absolute;
					// bottom: -36px;
					// right: 180rpx;

					width: 128rpx;
					height: 106rpx;
					// position: absolute;
					// bottom: -46px;
					// right: 200rpx;
					transform: rotateY(180deg);

					.arrow {
						width: 100%;
						height: 100%;
					}
				}

				.zi {
					// position: absolute;
					// bottom: -154rpx;
					// right: 178rpx;
					// bottom: -102rpx;
					// right: 142rpx;
					// left: 240rpx;
					line-height: 16rpx;
					padding-left: 10rpx;
				}
			}

			.nickname {
				padding: 0 24rpx;
				width: 326rpx;
				text-align: justify;

				.nick-nick {
					font-weight: 600;
				}
			}
		}

		.f-scroll {
			margin-top: 24rpx;

			.fscr-item {
				height: 80rpx;
				line-height: 80rpx;
			}
		}

		.ftip {
			color: #ff2200;
			font-size: 28rpx;
			margin-top: 200rpx;

			.fche {
				padding: 10rpx 32rpx;
				margin-top: 6rpx;
				border: 2rpx solid #ff0022;
				width: 200rpx;
				text-align: center;
			}
		}
	}

	// 选择主题
	.fmodel {
		height: 836rpx;
		width: 100%;

		.f-top {
			height: 100rpx;
			border-bottom: 1upx solid #ececec;
			padding-left: 24upx;
			background-color: #ffffff;
			border-radius: 32rpx 32rpx 0 0;
			font-size: 30rpx;

			.f-image {
				width: 78upx;
				height: 78upx;
				padding: 24upx;

				.f-img {
					width: 24upx;
					height: 24upx;
				}
			}
		}

		.scroll-fc {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			height: 80rpx;
			line-height: 60rpx;
			margin-top: 10rpx;
		}

		.cl-scroll {
			// width: 100%;
			padding: 0 24rpx;
			height: 80rpx;
			white-space: nowrap;

			.cl-item {
				padding: 0 24rpx;
				display: inline-flex;
			}
		}

		.cl-item-active {
			color: #FFFFFF;
			background-color: #353535;
		}

		.f-scroll {
			// height: 736upx;
			// height: 624upx;
			height: 560rpx;
			width: 100%;
			padding: 24rpx;
			background-color: #FFFFFF;
			font-size: 30rpx;

			.f-scroll-content {
				padding: 0 24upx;
				height: 995upx;
				width: 100%;
			}

			.f-item {
				width: 702upx;
				height: 100upx;
				// border: 1upx solid #cfcfcf;
				// margin-top: 17upx;
				text-align: center;
			}

			.f-item:last-child {
				// margin-bottom: 24upx;
			}

			.f-item-top {
				height: 159upx;
				position: relative;

				>image {
					height: 159upx;
					width: 100%;
				}

				>view {
					position: absolute;
					top: 0;
					width: 702upx;
					height: 159upx;
					padding: 0 24upx;
					color: #ffffff;
				}

				.dir-left-nowrap>button {
					width: 161upx;
					height: 56upx;
					line-height: 56upx;
					padding: 0;
					border: none;
					margin: 0;
					border-radius: 28upx;
					background-color: #ffffff;
					font-size: 26upx;
					text-align: center;
				}

				.f-text-content {
					padding-bottom: 25upx;
				}

				.f-big-text-dis text {
					line-height: 1;
				}

				.f-big-text-dis text:first-child {
					font-size: 56upx;
					font-weight: bold;
				}

				.f-big-text-dis text:last-child {
					font-size: 34upx;
					margin-left: 14upx;
				}

				.f-small-text {
					font-size: 24upx;
					margin-left: 27upx;
				}

				.f-big-text-pri text {
					line-height: 1;
				}

				.f-big-text-pri text:first-child {
					font-size: 27upx;
				}

				.f-big-text-pri text:last-child {
					font-size: 56upx;
					font-weight: bold;
				}
			}

			.f-item-bottom {
				height: 111upx;
				padding: 24upx;

				text {
					font-size: 22upx;
					color: #545454;
				}
			}
		}
	}

	.boddy {
		padding: 0 30rpx;
		margin-bottom: 10rpx;
	}

	.btns {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-wrap: wrap;
		box-sizing: border-box;
		margin: 10rpx 0;
	}

	.user-info {
		display: flex;
		justify-content: center;
		align-items: center;
		box-sizing: border-box;
		margin: 10rpx 0;

		view {
			display: flex;
			margin-right: 30rpx;
			align-items: center;
		}

		image {
			display: inline-block;
			width: 80rpx;
			border-radius: 50%;
		}

	}

	.tips {
		color: red;
		font-size: 26rpx;

	}

	.sixheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		background-color: #FFFFFF;
		display: flex;
		height: 120rpx;
		align-items: center;
		justify-content: space-between;
		z-index: 666;
		font-size: 28rpx;
		box-shadow: 0 0 20rpx -12rpx black;
		padding: 0 25rpx;
	}

	.flex {
		// position: fixed;
		// top: 0;
		// left: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		// background-color: #F7F7F7;
		padding: 24rpx 0;
		height: 120rpx;

		/* position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 999; */
		.sitem {
			height: 72rpx;
			line-height: 72rpx;
			font-size: 28rpx;

			.seaimg {
				// width: 36rpx;
				// height: 36rpx;
				// margin: 18rpx auto;
				width: 52rpx;
				height: 52rpx;
				margin: 10rpx auto;
			}
		}

		.fitem {
			margin-left: 20rpx;
			color: #ff2600;
		}

		.item {
			// width: 100rpx;
			height: 72rpx;
			line-height: 72rpx;
			position: relative;
			text-align: center;
			font-size: 28rpx;

			&.active:before {
				position: absolute;
				bottom: 0;
				left: 0;
				content: '';
				font-weight: 500;
				background: #342B2A;
				border-radius: 4rpx;
				width: 80rpx;
				left: 50%;
				transform: translateX(-50%);
				height: 8rpx;
			}
		}
	}

	// 暂无内容
	.nopt {
		text-align: center;
		line-height: 476rpx;
		font-size: 36rpx;
		margin-top: 120rpx;
	}

	// 返回顶部
	.quick-box {
		position: fixed;
		bottom: #{40rpx};
		right: #{48rpx};
		z-index: 100;
		transition: opacity 0.4s;
	}

	.quick-btn {
		width: #{80rpx};
		height: #{80rpx};
		margin-top: #{32rpx};
	}

	.no-goods {
		height: 360rpx;
		width: 100%;
		margin: 0 auto;
		text-align: center;
		line-height: 360rpx;
	}

	.release {
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		z-index: 100;
		width: 100rpx;
		height: 60rpx;
		background: #ff2600;
		color: #fff;
		border-radius: 10rpx 10rpx 0 0;
		text-align: center;
		font-size: 24rpx;
		line-height: 60rpx;
	}
</style>
